package com.xlong.taskthread;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSONObject;
import com.xlong.BeanEntity.ResponseMsg;
import com.xlong.BeanEntity.TaskEntity;
import com.xlong.service.ManageSpringBeans;
import com.xlong.service.TaskService;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ConsumerThread extends Thread {

	private TaskService taskService;
	
	private TaskEntity task;
    public ConsumerThread(TaskEntity task) {
        this.task = task;
    }
    
    //并发运行
    @SneakyThrows
    public void run() {
        
        log.info("开始"+System.currentTimeMillis());
        log.info("分配一个线程" + Thread.currentThread().getName() + "准备处理任务" + task.getTaskId());

				//把之前传进来的map参数取出来
        JSONObject json = task.getJson();
        taskService = ManageSpringBeans.getBean(TaskService.class);
        ResponseMsg<JSONObject> responseMsg = taskService.getResult(json);
        //String msg = "";
        //ResponseMsg<JSONObject> responseMsg = new ResponseMsg<JSONObject>(json.getIntValue("taskId"), msg, json);

        log.info(Thread.currentThread().getName() + "返回结果:{}", responseMsg);
        task.getTaskResult().setResult(responseMsg);
    }

}
